//
//  WJTabBarController.m
//  weibo
//
//  Created by 王俊 on 15/12/20.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "WJTabBarController.h"
#import "WJHomeViewController.h"
#import "WJMessageViewController.h"
#import "WJDiscoverViewController.h"
#import "WJProfileViewController.h"
#import "UIImage+WJImageExt.h"
#import "WJTabBar.h"
#import "WJNaviController.h"
#import "WJComposeController.h"



@interface WJTabBarController ()

//@property(nonatomic,strong) WJTabBar  *customTabBar;

@end

@implementation WJTabBarController

+ (void)initialize
{
    UITabBarItem *item = [UITabBarItem appearance];
    NSMutableDictionary *att = [[NSMutableDictionary alloc]init];
    att[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [item setTitleTextAttributes:att forState:UIControlStateSelected];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    WJTabBar *tabBar = [[WJTabBar alloc]initWithFrame:self.tabBar.frame];
    [self setValue:tabBar forKeyPath:@"tabBar"];
    [self setUpChildrenView];
}

- (void)setUpChildrenView
{
    WJHomeViewController *vc1 = [[WJHomeViewController alloc]init];
    [self addChildViewController:vc1];
    [self setUpOneChildView:vc1 title:@"首页" image:[UIImage imageNamed:@"tabbar_home"] selectedImage:[UIImage originalImageWithName:@"tabbar_home_selected"] andBadgeValue:nil];
    

    WJMessageViewController *vc2 = [[WJMessageViewController alloc]init];
    [self setUpOneChildView:vc2 title:@"消息" image:[UIImage imageNamed:@"tabbar_message_center"] selectedImage:[UIImage originalImageWithName:@"tabbar_message_center_selected"] andBadgeValue:nil];
    
    WJDiscoverViewController  *vc3 = [[WJDiscoverViewController alloc]init];
    [self setUpOneChildView:vc3 title:@"发现" image:[UIImage imageNamed:@"tabbar_discover"] selectedImage:[UIImage originalImageWithName:@"tabbar_discover_selected"] andBadgeValue:nil];

    WJProfileViewController *vc4 = [[WJProfileViewController alloc]init];
    [self setUpOneChildView:vc4 title:@"我" image:[UIImage imageNamed:@"tabbar_profile"] selectedImage:[UIImage originalImageWithName:@"tabbar_profile_selected"] andBadgeValue:nil];

    
}

- (void)setUpOneChildView:(UIViewController*)controller title:(NSString*)title image:(UIImage*)image selectedImage:(UIImage*)selectedImage andBadgeValue:(NSString*)value
{
    controller.title = title;
    controller.tabBarItem.image = image;
    controller.tabBarItem.selectedImage = selectedImage;
    controller.tabBarItem.badgeValue = value;
    WJNaviController *navi = [[WJNaviController alloc]initWithRootViewController:controller];
//    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:controller];
    [self addChildViewController:navi];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)tabBar:(WJTabBar *)tabBar selectedPlusButton:(UIButton *)plusBtn
{
    WJComposeController *vc = [[WJComposeController alloc]init];
    WJNaviController *navi = [[WJNaviController alloc]initWithRootViewController:vc];
    [self presentViewController:navi animated:true completion:nil];
}


@end
